package cn.anecansaitin.jep.interpreter.evaluators;

import cn.anecansaitin.jep.interpreter.Interpreter;
import cn.anecansaitin.jep.parser.ast.node.expression.*;
import cn.anecansaitin.jep.parser.ast.node.expression.literal.BooleanLiteral;
import cn.anecansaitin.jep.types.TypeInfo;

public class BooleanEvaluator {
    public static boolean evaluate(Expression expression) {
        return switch (expression) {
            case Unary unary -> unary(unary);
            case Binary binary -> binary(binary);
            case Ternary ternary -> ternary(ternary);
            case Grouping grouping -> evaluate(grouping.expression());
            case BooleanLiteral booleanLiteral -> booleanLiteral.value();
            default -> throw Interpreter.markError(expression, "未实现的运算符");
        };
    }

    private static boolean unary(Unary unary) {
        TypeInfo resultType = unary.expression().resultType();

        if (resultType == TypeInfo.BOOLEAN) {
            return !BooleanEvaluator.evaluate(unary.expression());
        } else {
            throw Interpreter.markError(unary, "无法将" + unary.operator() + "运算符用于" + resultType);
        }
    }

    private static boolean binary(Binary binary) {
        Expression left = binary.left();
        Expression right = binary.right();
        TypeInfo leftType = left.resultType();
        TypeInfo rightType = right.resultType();

        return switch (binary.operator().type()) {
            case AND -> {
                if (leftType == TypeInfo.BOOLEAN && rightType == TypeInfo.BOOLEAN) {
                    yield BooleanEvaluator.evaluate(left) && BooleanEvaluator.evaluate(right);
                } else {
                    throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                }
            }
            case OR -> {
                if (leftType == TypeInfo.BOOLEAN && rightType == TypeInfo.BOOLEAN) {
                    yield BooleanEvaluator.evaluate(left) || BooleanEvaluator.evaluate(right);
                } else {
                    throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                }
            }
            case EQUAL -> switch (leftType) {
                case BOOLEAN -> {
                    if (rightType == TypeInfo.BOOLEAN) {
                        yield BooleanEvaluator.evaluate(left) == BooleanEvaluator.evaluate(right);
                    } else {
                        throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    }
                }
                case CHAR -> {
                    char leftValue = CharEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue == rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue == rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue == rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue == rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue == rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                case INT -> {
                    int leftValue = IntEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue == rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue == rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue == rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue == rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue == rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                case LONG -> {
                    long leftValue = LongEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue == rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue == rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue == rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue == rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue == rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                case FLOAT -> {
                    float leftValue = FloatEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue == rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue == rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue == rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue == rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue == rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                case DOUBLE -> {
                    double leftValue = DoubleEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue == rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue == rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue == rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue == rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue == rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
            };
            case NOT_EQUAL -> switch (leftType) {
                case BOOLEAN -> {
                    if (rightType == TypeInfo.BOOLEAN) {
                        yield BooleanEvaluator.evaluate(left) != BooleanEvaluator.evaluate(right);
                    } else {
                        throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    }
                }
                case CHAR -> {
                    char leftValue = CharEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue != rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue != rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue != rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue != rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue != rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                case INT -> {
                    int leftValue = IntEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue != rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue != rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue != rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue != rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue != rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                case LONG -> {
                    long leftValue = LongEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue != rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue != rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue != rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue != rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue != rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                case FLOAT -> {
                    float leftValue = FloatEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue != rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue != rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue != rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue != rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue != rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                case DOUBLE -> {
                    double leftValue = DoubleEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue != rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue != rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue != rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue != rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue != rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
            };
            case LESS_THAN -> switch (leftType) {
                case CHAR -> {
                    char leftValue = CharEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue < rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue < rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue < rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue < rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue < rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                case INT -> {
                    int leftValue = IntEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue < rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue < rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue < rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue < rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue < rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                case LONG -> {
                    long leftValue = LongEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue < rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue < rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue < rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue < rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue < rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                case FLOAT -> {
                    float leftValue = FloatEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue < rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue < rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue < rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue < rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue < rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                case DOUBLE -> {
                    double leftValue = DoubleEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue < rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue < rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue < rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue < rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue < rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
            };
            case GREATER_THAN -> switch (leftType) {
                case CHAR -> {
                    char leftValue = CharEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue > rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue > rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue > rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue > rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue > rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                case INT -> {
                    int leftValue = IntEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue > rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue > rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue > rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue > rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue > rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                case LONG -> {
                    long leftValue = LongEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue > rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue > rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue > rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue > rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue > rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                case FLOAT -> {
                    float leftValue = FloatEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue > rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue > rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue > rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue > rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue > rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                case DOUBLE -> {
                    double leftValue = DoubleEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue > rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue > rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue > rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue > rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue > rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
            };
            case LESS_THAN_EQUAL -> switch (leftType) {
                case CHAR -> {
                    char leftValue = CharEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue <= rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue <= rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue <= rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue <= rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue <= rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                case INT -> {
                    int leftValue = IntEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue <= rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue <= rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue <= rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue <= rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue <= rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                case LONG -> {
                    long leftValue = LongEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue <= rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue <= rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue <= rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue <= rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue <= rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                case FLOAT -> {
                    float leftValue = FloatEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue <= rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue <= rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue <= rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue <= rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue <= rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                case DOUBLE -> {
                    double leftValue = DoubleEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue <= rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue <= rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue <= rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue <= rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue <= rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
            };
            case GREATER_THAN_EQUAL -> switch (leftType) {
                case CHAR -> {
                    char leftValue = CharEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue >= rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue >= rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue >= rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue >= rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue >= rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                case INT -> {
                    int leftValue = IntEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue >= rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue >= rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue >= rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue >= rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue >= rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                case LONG -> {
                    long leftValue = LongEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue >= rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue >= rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue >= rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue >= rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue >= rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                case FLOAT -> {
                    float leftValue = FloatEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue >= rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue >= rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue >= rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue >= rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue >= rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                case DOUBLE -> {
                    double leftValue = DoubleEvaluator.evaluate(left);

                    yield switch (rightType) {
                        case CHAR -> {
                            char rightValue = CharEvaluator.evaluate(right);
                            yield leftValue >= rightValue;
                        }
                        case INT -> {
                            int rightValue = IntEvaluator.evaluate(right);
                            yield leftValue >= rightValue;
                        }
                        case LONG -> {
                            long rightValue = LongEvaluator.evaluate(right);
                            yield leftValue >= rightValue;
                        }
                        case FLOAT -> {
                            float rightValue = FloatEvaluator.evaluate(right);
                            yield leftValue >= rightValue;
                        }
                        case DOUBLE -> {
                            double rightValue = DoubleEvaluator.evaluate(right);
                            yield leftValue >= rightValue;
                        }
                        default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
                    };
                }
                default -> throw Interpreter.markError(binary, "无法将" + binary.operator() + "运算符用于" + leftType + "和" + rightType);
            };
            default -> throw Interpreter.markError(binary, "未实现的运算符");
        };
    }

    private static boolean ternary(Ternary ternary) {
        boolean condition = BooleanEvaluator.evaluate(ternary.condition());
        Expression trueExpression = ternary.trueValue();
        Expression falseExpression = ternary.falseValue();

        if (condition) {
            return switch (trueExpression.resultType()) {
                case BOOLEAN -> BooleanEvaluator.evaluate(trueExpression);
                default -> throw Interpreter.markError(ternary, "不支持的表达式结果类型");
            };
        } else {
            return switch (falseExpression.resultType()) {
                case BOOLEAN -> BooleanEvaluator.evaluate(falseExpression);
                default -> throw Interpreter.markError(ternary, "不支持的表达式结果类型");
            };
        }
    }
}
